package gl.android.biyiqing.fragment;

import gl.API;
import gl.adapter.SimpleAdapter.OnItemChildViewClick;
import gl.android.biyiqing.R;
import gl.android.biyiqing.competent.OnSelectGiftToSendItemClickListener;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.TextView;

public class GiftFragment extends BaseListFragmet {
	// Content View Elements

	// Content View Elements

	// Content View Elements

	private TextView empty;
	private AbsListView list;
	String NOTFOUND = "没有礼物\n再试一次吧！";

	private void bindViews() {

		empty = (TextView) findViewById(R.id.empty);
		list = (AbsListView) findViewById(android.R.id.list);
		list.setEmptyView(empty);
		empty.setText("正在加载..");
		empty.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				initData();
			}
		});
	}

	public GiftFragment() {
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tuserid = getArguments().getString(KEY_TO_USER_ID);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = inflater.inflate(R.layout.gridview_empty, container,
				false);
		bindViews();
		initData();
		return rootView;
	}

	String type_gift = "0";// all
	String tuserid = "";
	/**
	 * 送礼物的留言
	 */
	private String message;

	private void initData() {
		initAbsListView(getListView(), API.URL + "GetGiftList?type=%s",
				new Object[] { type_gift }, R.layout.item_list_gif,
				new String[] { "giftname", "imgurl", "intro","points" }, new int[] {
						R.id.tv_nick, R.id.iv_avator, R.id.tv_jianjie, R.id.age,R.id.sent });
	}
	@Override
	protected OnItemChildViewClick getOnItemChildViewCilck() {
		return new OnSelectGiftToSendItemClickListener(dataJSONArray.toString(), tuserid, message);
	}
	@Override
	public Object getOnItemListener(String[] from, String t)
			throws JSONException {
		return new OnSelectGiftToSendItemClickListener(new JSONObject(t).get(
				"data").toString(), tuserid, message);
	}
}
